package server.base;

import java.io.IOException;

/**
 * @ClassName HttpServlet
 * @Description TODO
 * @Auth ying.xiao
 * @Date 2021/3/6
 * @Version 1.0.0
 */
public abstract class HttpServlet implements Servlet {

    protected abstract void doPost(HttpRequest request, HttpResponse response) throws IOException;

    protected abstract void doGet(HttpRequest request, HttpResponse response) throws IOException;

//    @Override
//    public void service(HttpRequest request, HttpResponse response) throws IOException {
//        if ("GET".equalsIgnoreCase(request.getMethod())){
//            doGet(request,response);
//        }else{
//            doPost(request,response);
//        }
//    }


    public void service(HttpRequest request, HttpResponse response) throws IOException {
        if ("GET".equalsIgnoreCase(request.getMethod())){
            doGet(request,response);
        }else{
            doPost(request,response);
        }
    }
}
